package com.longge;

public class GetTargetCopy {

    public final TreeNode getTargetCopy(final TreeNode original, final TreeNode cloned, final TreeNode target) {

        return dfs(cloned, target);
    }

    private TreeNode dfs(TreeNode cloned, TreeNode target) {
        if (cloned == null) return null;
        if (cloned.val == target.val) return cloned;
        TreeNode left = dfs(cloned.left, target);
        TreeNode right = dfs(cloned.right, target);
        return left == null ? right : left;
    }
}
